home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / MACVOGL- / EXAMPLES / WORLD.C < prev   
C/C++ Source or Header  |  1992-07-19  |  3KB  |  161 lines

  1. #include <stdio.h>
  2.  
  3. #ifdef SGI
  4. #include "gl.h"
  5. #include "device.h"
  6. #else
  7. #include "vogl.h"
  8. #include "vodevice.h"
  9. #endif
  10.  
  11. #ifndef PI
  12. #define PI    3.1415926535
  13. #endif
  14.  
  15. #ifndef TC
  16. #include <math.h>
  17. #else
  18. extern double    sin(), cos();
  19. #endif
  20.  
  21. #define RADIUS    10.0
  22. #define    SPHERE    1L
  23.  
  24. void    showroundtext(), makesphere();
  25.  
  26. /*
  27.  * most of the things in this program have been done before but it has
  28.  * a certain novelty value.
  29.  */
  30. main()
  31. {
  32.     int    i;
  33.     short    val;
  34.     float    r, z, a;
  35.  
  36.     winopen("world");
  37.     qdevice(KEYBD);
  38.     unqdevice(INPUTCHANGE);
  39.  
  40.     hfont("futura.m");
  41.  
  42.     perspective(800, 1.0, 0.001, 50.0);
  43.     lookat(13.0, 13.0, 8.0, 0.0, 0.0, 0.0, 0);
  44.  
  45.     color(BLACK);
  46.     clear();
  47.  
  48.     makesphere();
  49.  
  50.     /*
  51.      * draw the main one in cyan
  52.      */
  53.     color(CYAN);
  54.  
  55.     callobj(SPHERE);
  56.  
  57.     /*
  58.      * draw a smaller one outside the main one in white
  59.      */
  60.     color(WHITE);
  61.  
  62.     pushmatrix();
  63.         translate(0.0, -1.4 * RADIUS, 1.4 * RADIUS);
  64.         scale(0.3, 0.3, 0.3);
  65.         callobj(SPHERE);
  66.     popmatrix();
  67.  
  68.     /*
  69.      * scale the text
  70.      */
  71.     hboxfit(2.0 * PI * RADIUS, 0.25 * RADIUS, 31);
  72.  
  73.     /*
  74.      * now write the text in rings around the main sphere
  75.      */
  76.  
  77.     color(GREEN);
  78.     showroundtext("Around the world in eighty days ");
  79.  
  80.     color(BLUE);
  81.     /*
  82.      * note: that software text is rotated here as
  83.      * anything else would be whether you use textang
  84.      * or rotate depends on what you are trying to do.
  85.      * Experience is the best teacher here.
  86.      */
  87.     rotate(900, 'x');
  88.     showroundtext("Around the world in eighty days ");
  89.  
  90.     color(RED);
  91.     rotate(900, 'z');
  92.     showroundtext("Around the world in eighty days ");
  93.  
  94.     qread(&val);
  95.  
  96.     gexit();
  97. }
  98.  
  99. /*
  100.  * showroundtext
  101.  *
  102.  *    draw string str wrapped around a circle in 3d
  103.  */
  104. void
  105. showroundtext(str)
  106.     char    *str;
  107. {
  108.     int    i, inc;
  109.  
  110.     inc = 3600 / strlen(str);
  111.  
  112.     for (i = 0; i < 3600; i += inc) {
  113.         pushmatrix();
  114.             /*
  115.              * find the spot on the edge of the sphere
  116.              * by making it (0, 0, 0) in world coordinates
  117.              */
  118.             rotate(i, 'y');
  119.             translate(0.0, 0.0, RADIUS);
  120.  
  121.             move(0.0, 0.0, 0.0);
  122.  
  123.             hdrawchar(*str++);
  124.         popmatrix();
  125.     }
  126. }
  127.  
  128. /*
  129.  * makesphere
  130.  *
  131.  *    create the sphere object
  132.  */
  133. void
  134. makesphere()
  135. {
  136.     float    i, r, z, a;
  137.  
  138.     makeobj(SPHERE);
  139.  
  140.         for (i = 0; i < 180; i += 20) {
  141.             pushmatrix();
  142.                 rotate((int)i * 10, 'y');
  143.                 circ(0.0, 0.0, RADIUS);
  144.             popmatrix();
  145.         }
  146.         
  147.         pushmatrix();
  148.             rotate(900, 'x');
  149.             for (a = -90.0; a < 90.0; a += 20.0) {
  150.                 r = RADIUS * cos((double)a * PI / 180.0);
  151.                 z = RADIUS * sin((double)a * PI / 180.0);
  152.                 pushmatrix();
  153.                     translate(0.0, 0.0, -z);
  154.                     circ(0.0, 0.0, r);
  155.                 popmatrix();    
  156.             }
  157.         popmatrix();
  158.  
  159.     closeobj();
  160. }
  161.